<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
$(function(){
	$(".ajax_provider").autocomplete("<?=url('DataCenter::Purchase/Provider')?>").result(function(event, data, formatted){});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"50%", height:"50%", iframe:true});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>入库日期</th>
	<td>
		<input type="text" name="begin_storage_audit_time" class="datepicker" value="<?=isset($_GET['begin_storage_audit_time'])?$_GET['begin_storage_audit_time']:''?>" /> to
		<input type="text" name="end_storage_audit_time" class="datepicker" value="<?=isset($_GET['end_storage_audit_time'])?$_GET['end_storage_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>跟进人员</th>
	<td>
		<select name="follow_user_id">
			<option value="">请选择..</option>
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if (isset($_GET['follow_user_id'])&&$_GET['follow_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>供应商</th>
	<td><input type="text" name="ajax_provider" class="ajax_provider" value="<?=isset($_GET['ajax_provider'])?$_GET['ajax_provider']:''?>" /></input></td>
</tr>
<tr>
	<td><input type="hidden" name="is_search" value="1" /></td>
	<td><input type="submit" class="button" value="查询" /></td>
	<?if (isset($_GET['is_search'])):?>
	<td><a href="<?=url('Datacenter::Purchase/StatisticsDownload', array('url_arr' => $url_arr_json))?>">下载报表</a></td>
	<?endif;?>
</tr>
</table>
</form></fieldset>
<?if (isset($result)):?>
<table width="80%" class="list_table">
<tr>
	<th>ID</th>
	<th>供应商名称</th>
	<th>合作日期</th>
	<th>产品类别 </th>
	<th>采购入库总金额</th>
	<th>库存总金额</th>
	<th>跟进人</th>
</tr>
<?$purchase_total = $stock_total = 0;?>
<?foreach ($result as $r):?>
<?
$purchase_total += $r['purchase_amount'];
$stock_total += $r['stock_amount'];
?>
<tr>
	<td><?=$r['id']?></td>
	<td><a class="detail" href="<?=url('Datacenter::Purchase/ProviderDetail', array('id' => $r['id']));?>"><?=$r['name']?></a></td>
	<td><?=$r['create_time']?></td>
	<td>
		<?foreach ($r['categories'] as $rc):?>
		<?=$rc['name'] . "\n";?> 
		<?endforeach;?>
	</td>
	<td><?=$r['purchase_amount']?></td>
	<td><?=$r['stock_amount']?></td>
	<td><?=$r['follow_user_name']?></td>
</tr>
<?endforeach;?>
<tr>
	<td colspan="4" align="right">总计：</td>
	<td><?=number_format($purchase_total, 2)?></td>
	<td><?=number_format($stock_total, 2)?></td>
	<td></td>
</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>